<template>
  <div className="app-container">
    <div className="table-container">
      <base-list
        ref="table"
        url="/user_info"
        :options="options"
        :columns="columns"
        :format="format"
        :rules="rules"
        image-suffix="avatar-"
        permission="ADMIN"
        @reloadOptions="handleGetOptions"
      />
    </div>
  </div>
</template>

<script>
import {getBaseList, getBaseOptions} from '@/api/common'
import BaseList from '@/components/BaseList/index.vue'

export default {
  name: 'UserInfo',
  components: {BaseList},
  data() {
    return {
      columns: [
        {show: true, edit: false, width: '100', key: 'id', fixed: true, label: 'ID', tooltip: 'ID', type: 'NUMBER', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'nickName', label: '昵称', tooltip: '昵称', type: 'WORD', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '80', key: 'avatar', label: '头像', tooltip: '头像', type: 'IMAGE'},
        {show: true, edit: true, width: '100', key: 'mbti', label: 'MBTI', tooltip: 'MBTI', type: 'WORD'},
        {show: true, edit: true, width: 'auto',minWidth: '80', key: 'sex', label: '性别', tooltip: '性别', type: 'DICTIONARY', optionKey: 'sexOptions',queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '80', key: 'marry', label: '已婚', tooltip: '已婚', type: 'DICTIONARY', optionKey: 'ynOptions',queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '80', key: 'child', label: '有孩子', tooltip: '有孩子', type: 'DICTIONARY', optionKey: 'ynOptions',queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'birthDay', label: '生日', tooltip: '生日', type: 'DATE',queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '300', key: 'description', label: '签名', tooltip: '签名', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createTime', label: '创建时间', tooltip: '创建时间', type: 'DATE_TIME'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'updateTime', label: '更新时间', tooltip: '更新时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'updateUser', label: '修改人', tooltip: '修改人', type: 'WORD'},
      ],
      format: {
        createUser: (data, index) => {
          return data.createUser ? data.createUser.nickName + '('+data.createUser.id+')' : ''
        },
        updateUser: (data, index) => {
          return data.updateUser ? data.updateUser.nickName + '('+data.updateUser.id+')' : ''
        }
      },
      rules: {
        add: {
          nickName: [{required: true, message: '昵称必填!', trigger: 'blur'}],
          avatar: [{required: true, message: '头像必填!', trigger: 'blur'}],
          description: [{required: true, message: '签名必填!', trigger: 'blur'}],
          sex: [{required: true, message: '性别必填!', trigger: 'blur'}],

        },
        edit: {
          id: [{required: true, message: '请选择数据!', trigger: 'change'}],
          nickName: [{required: true, message: '昵称必填!', trigger: 'blur'}],
          avatar: [{required: true, message: '头像必填!', trigger: 'blur'}],
          description: [{required: true, message: '签名必填!', trigger: 'blur'}],
          sex: [{required: true, message: '性别必填!', trigger: 'blur'}],

        }
      },
      options: {
        sexOptions: [{id: 'NONE', name: '无', type: 'info'},{id: 'MALE', name: '男', type: 'primary'},{id: 'FEMALE', name: '女', type: 'danger'}],
        ynOptions: [{id: 'O', name: '空', type: 'info'},{id: 'Y', name: '是', type: 'primary'},{id: 'N', name: '否', type: 'success'}],
      }
    }
  },

  created() {
    this.handleGetOptions()
  },
  mounted() {
  },
  methods: {
    handleGetOptions() {
      const options = JSON.parse(localStorage.getItem('allOptions'))
      if (options) {
        this.options = Object.assign(this.options, options)
      }
    }
  }
}
</script>


